//
//  choseBankTableViewController.m
//  1243
//
//  Created by ym on 16/5/26.
//  Copyright © 2016年 1243. All rights reserved.
//

#import "choseBankTableViewController.h"
#import "CardTypeTableViewCell.h"
#import "NetWorkTools.h"
@interface choseBankTableViewController ()
@property(nonatomic,strong)NSMutableArray *boolArray;
@property(nonatomic,strong)NSArray *dataArr;
@property (nonatomic, strong) NSString *str;
@end

@implementation choseBankTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"卡类型";
    [self data];
    
}

- (NSMutableArray *)boolArray
{
    if (!_boolArray) {
        _boolArray = [NSMutableArray arrayWithObjects:@"1",@"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", @"0", nil];
    }
    return _boolArray;
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *identifier= @"CardTypeTableViewCell";
    
    CardTypeTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    
    if (cell==nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"CardTypeTableViewCell" owner:nil options:nil] lastObject];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    
    
    //
    if (self.dataArr.count) {
        NSString*string = self.dataArr[indexPath.row];
        //    [string substringFromIndex:15];
        self.str = string;
      
        //          NSLog(@"截取的值为：%@",str);
        cell.BankLabel.text = [NSString stringWithFormat:@"%@",self.dataArr[indexPath.row]];
        
        
    }else{
        
        cell.BankLabel.text = @"";
        cell.selectImageView.hidden= YES;
    }
  
    
    return cell;
}


#pragma mark >>>>>>>> 代理方法
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 20;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString*string = self.dataArr[indexPath.row];
    self.str = string;
  
    [[NSNotificationCenter defaultCenter] postNotificationName:@"choseCard" object:nil userInfo:@{@"name":string}];
    [self.navigationController popViewControllerAnimated:YES];
    for (NSInteger i=0; i<self.boolArray.count; i++) {
        if (indexPath.row == i) {
            self.boolArray[i] = @"1";
        }else{
            self.boolArray[i] = @"0";
        }
    }
    [self.tableView reloadData];
}

- (void)data{
   self.dataArr  = [NSMutableArray arrayWithObjects:@"中国人民银行",@"国家开发银行",@"中国进出口银行", @"中国农业发展银行", @"中国工商银行", @"中国建设银行", @"中国银行", @"中国农业银行", @"交通银行", @"招商银行", @"中国邮政储蓄银行", @"中信银行", @"光大银行", @"民生银行", @"兴业银行", @"华夏银行", @"上海银行", @"平安银行", @"浙商银行",@"杭州银行",nil];
}

@end
